{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## python practice\n",
    "[地址](https://pythonbasics.org/Exercises/)\n",
    "### 1.variables\n",
    "+ Make a program that displays several numbers.\n",
    "+ Make a program that solves and shows the summation of 64 + 32.\n",
    "+ Do the same as in 2, but make it sum x + y."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "96\n",
      "96\n"
     ]
    }
   ],
   "source": [
    "x = 64\n",
    "y = 32\n",
    "print(x + y)\n",
    "z = x + y\n",
    "print(z)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. strings\n",
    "+ Make a program that displays your favourite actor/actress.\n",
    "+ Try to print the word ‘lucky’ inside s.\n",
    "+ Try to print the day, month, year in the form “Today is 2/2/2016”."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "my favourite actress isli\n",
      "My lucky number is 7, what is yours?\n",
      "Today is 20/3/2019\n"
     ]
    }
   ],
   "source": [
    "youFavouriteActress = \"li\"\n",
    "print(\"my favourite actress is\" + youFavouriteActress)\n",
    "s = \"My lucky number is %d, what is yours?\" % 7  # combine the number and text\n",
    "print(s)\n",
    "print(\"Today is 20/3/2019\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. string replace\n",
    ">Python has builtin support for string replacement. A string is a variable that contains text data\n",
    "\n",
    "---------------\n",
    ">> 关于repalce的官方文档。  \n",
    ">>bytes.replace(old, new[, count])  \n",
    ">>bytearray.replace(old, new[, count])  \n",
    ">>Return a copy of the sequence with all occurrences of subsequence old replaced by new. If the optional argument count is given, only the first count occurrences are replaced.  \n",
    ">>The subsequence to search for and its replacement may be any bytes-like object.  \n",
    ">>Note The bytearray version of this method does not operate in place - it always produces a new object, even if no changes were made.  \n",
    "\n",
    ">> 人话就是：会返回一个新的数据，但是是用新的代替了就得，count默认是全部替换，如果count写几，就换几个。count是整数,old and new must be str\n",
    "\n",
    ">> 但是问题是bytes  and bytearray是什么东西了？\n",
    "\n",
    "+ Try the replace program\n",
    "+ Can a string be replaced twice?\n",
    "+ Does replace only work with words or also phrases?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello Universe\n",
      "Hello World World World\n",
      "Hello Universe World World\n",
      "Hello Universe Universe World\n",
      "Hello you you you\n",
      "Hello 1 1 1\n",
      "64\n"
     ]
    }
   ],
   "source": [
    "s = \"Hello World\"\n",
    "s = s.replace(\"World\",\"Universe\")\n",
    "print(s)\n",
    "# 这里其实涉及到一个问题就是，啥时候用s. 啥时候用一个函数。。\n",
    "s = \"Hello World World World\"\n",
    "r= s.replace(\"World\",\"Universe\",1)\n",
    "r1 =s.replace(\"World\",\"Universe\",2)\n",
    "w =s.replace(\"World\",\"you\")\n",
    "w1 =s.replace(\"World\",\"you\").replace(\"you\",\"1\")\n",
    "\n",
    "# x = [1,1,2,5].replace(1,3)   这里会报错的。\n",
    "#x =125689.replace(1,2)\n",
    "print(s)  # s not change\n",
    "print(r)\n",
    "print(r1)\n",
    "print(w)\n",
    "print(w1)\n",
    "print(x)  #在这个cellipynb文件里面，所有的x都是通用的啊。6666\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "123,124,132,134,142,143,213,214,231,234,241,243,312,314,321,324,341,342,412,413,421,423,431,432,"
     ]
    }
   ],
   "source": [
    "#这里有四个数字，分别是：1、2、3、4\n",
    "# 提问：能组成多少个互不相同且无重复数字的三位数？各是多少？\n",
    "\n",
    "for a in range(1,5):\n",
    "    for b in range(1,5):\n",
    "        for c in range(1,5):\n",
    "            if a !=b and b !=c and c !=a:\n",
    "                print(a,b,c,sep=\"\",end=\",\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "净利润: 150000\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "13750.0\n"
     ]
    }
   ],
   "source": [
    "# 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时，奖金可提10%；利润高于10万元，低于20万元时，\n",
    "# 低于10万元的部分按10%提成，高于10万元的部分，可提成7.5%；20万到40万之间时，高于20万元的部分，可提成5%；\n",
    "# 40万到60万之间时高于40万元的部分，可提成3%；60万到100万之间时，高于60万元的部分，可提成1.5%，高于100万元时，\n",
    "# 超过100万元的部分按1%提成.\n",
    "\n",
    "# profile =int(input(\"请输入今年利润，单位元\"))\n",
    "# if profile < 100000:\n",
    "#     get_money = profile * 0.1\n",
    "# elif profile >100000 and profile <200000:\n",
    "#     get_money = (profile - 100000)*0.075 +10000\n",
    "# elif profile >200000 and profile < 400000:\n",
    "#     get_money = (profile - 200000) * 0.05 + 7500 + 10000\n",
    "# elif profile >400000 and profile < 600000:\n",
    "#     get_money =(profile -400000)* 0.03 +5000+7500+10000\n",
    "# elif profile > 600000 and profile < 1000000:\n",
    "#     get_money =(profile -600000)*0.015 +10000 + 7500 +10000\n",
    "# elif profile >1000000:\n",
    "#     get_money = (profile -1000000) *0.01 + 6000 +6000+10000+7500+10000\n",
    "# print(get_money)\n",
    "\n",
    "\n",
    "i = int(input('净利润:'))\n",
    "arr = [1000000,600000,400000,200000,100000,0]\n",
    "rat = [0.01,0.015,0.03,0.05,0.075,0.1]\n",
    "r = 0\n",
    "for idx in range(0,6):\n",
    "    if i>arr[idx]:\n",
    "        r+=(i-arr[idx])*rat[idx]\n",
    "#         print ((i-arr[idx])*rat[idx])\n",
    "        i=arr[idx]\n",
    "print(r)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'int'>\n",
      "True\n",
      "21\n",
      "261\n",
      "1581\n"
     ]
    }
   ],
   "source": [
    "# 简述：一个整数，它加上100和加上268后都是一个完全平方数\n",
    "# 提问：请问该数是多少？\n",
    "# import math\n",
    "# print(math.sqrt(9))\n",
    "# type(\"hellow\")\n",
    "# for i in range(0,10000):\n",
    "#     if type(math.sqrt(i + 100) ==int) and type(math.sqrt(i+268) ==int):\n",
    "#         print(i) \n",
    "y = 9\n",
    "z= type(y)\n",
    "print(type(y))\n",
    "print(z == int)\n",
    "\n",
    "import math\n",
    "for i in range(10000):\n",
    "#转化为整型值\n",
    "    x = int(math.sqrt(i + 100))\n",
    "    y = int(math.sqrt(i + 268))\n",
    "    if(x * x == i + 100) and (y * y == i + 268):\n",
    "        print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 简述：要求输入某年某月某日\n",
    "# 提问：求判断输入日期是当年中的第几天？\n",
    "\n",
    "today_year =int(input(\"年\"))\n",
    "today_month =int(input(\"月\"))\n",
    "today_day =int(input(\"日\"))\n",
    "\n",
    "day = [31,28,31,30,31,30,31,30,30,31,30,31]\n",
    "if today_month >12:\n",
    "    print(\"it's error days\")\n",
    "how_much_days =0\n",
    "for i in day[0:today_month-1]:\n",
    "    how_much_days+= i\n",
    "how_much_days =how_much_days+ today_day\n",
    "print(\"今天是今年的第%d天\"%how_much_days)\n",
    "    \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "list assignment index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-3-7c85a2b5e34f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m     35\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     36\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 37\u001b[1;33m \u001b[0morder1\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     38\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     39\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m<ipython-input-3-7c85a2b5e34f>\u001b[0m in \u001b[0;36morder1\u001b[1;34m(x, y, z)\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0morder1\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mz\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m     \u001b[0morder_array\u001b[0m \u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 6\u001b[1;33m     \u001b[0morder_array\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"hello\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      7\u001b[0m     \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0morder_array\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      8\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0mx\u001b[0m \u001b[1;33m<\u001b[0m \u001b[0my\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mx\u001b[0m \u001b[1;33m<\u001b[0m \u001b[0mz\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mIndexError\u001b[0m: list assignment index out of range"
     ]
    }
   ],
   "source": [
    "# 整数顺序排列问题简述：任意三个整数类型，x、y、z\n",
    "# 提问：要求把这三个数，按照由小到大的顺序输出\n",
    "\n",
    "# def order1(x,y,z):\n",
    "#     order_array =[]\n",
    "#     if x < y and x < z:\n",
    "#         order_array.append(x)\n",
    "#         if y < z:\n",
    "#             order_array.append(y)\n",
    "#             order_array.append(z)\n",
    "#         else:\n",
    "#             order_array[1]=z\n",
    "#             order_array[2]=y\n",
    "#     if y < x and y < z:\n",
    "#         order_array[0] =y\n",
    "#         if x < z:\n",
    "#             order_array[1]=x\n",
    "#             order_array[2] =z\n",
    "#         else:\n",
    "#             order_array[1] =z\n",
    "#             order_array[2]=x\n",
    "#     if z < x and z < y:\n",
    "#         order_array[0] =z\n",
    "#         if x < y:\n",
    "#             order_array[1] =x\n",
    "#             order_array[2]=y\n",
    "#         else: \n",
    "#             order_array[1] =y\n",
    "#             order_array[2]= x\n",
    "            \n",
    "#     for i in order_arrar:\n",
    "#         print(i,end=\"-\")\n",
    "    \n",
    "    \n",
    "# order1(1,5,2)  sb \n",
    "\n",
    "\n",
    "\n",
    "l = []\n",
    "for i in range(3):\n",
    "    x = int(raw_input('integer:\\n'))\n",
    "    l.append(x)\n",
    "l.sort()\n",
    "print(l)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "           1            1\n",
      "           2            3\n",
      "           5            8\n",
      "\n",
      "          13           21\n",
      "          34           55\n",
      "          89          144\n",
      "\n",
      "         233          377\n",
      "         610          987\n",
      "        1597         2584\n",
      "\n",
      "        4181         6765\n",
      "       10946        17711\n",
      "       28657        46368\n",
      "\n",
      "       75025       121393\n",
      "      196418       317811\n",
      "      514229       832040\n",
      "\n",
      "     1346269      2178309\n",
      "     3524578      5702887\n",
      "     9227465     14930352\n",
      "\n",
      "    24157817     39088169\n",
      "    63245986    102334155\n"
     ]
    }
   ],
   "source": [
    "# 简述：话说有一对可爱的兔子，出生后的第三个月开始，每一月都会生一对小兔子。当小兔子长到第三个月后，也会每个月再生一对小小兔子.\n",
    "\n",
    "# 问题：假设条件，兔子都不死的情况下，问每个月的兔子总数为多少？\n",
    "\n",
    "a1 = 1\n",
    "b2 = 1\n",
    "for i in range(1,21):\n",
    "    print('%12ld %12ld' % (a1,b2))\n",
    "    if (i % 3) == 0:\n",
    "        print()\n",
    "    a1 = a1 + b2\n",
    "    b2 = a1 + b2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "153-370-371-407-1634-8208-9474-54748-92727-93084-548834-1741725-4210818-9800817-9926315-24678050-24678051-"
     ]
    }
   ],
   "source": [
    "# 什么是水仙花数？百度一下：水仙花数是指一个 n 位正整数 ( n≥3 )，它的每个位上的数字的 n 次幂之和等于它本身。\n",
    "# （例如：1^3 + 5^3+ 3^3 = 153）。\n",
    "# 首先判断一个数是不是水仙花数。。\n",
    "# 判断某个区间里面有多少个水仙花数.\n",
    "def if_sxh_num(num):\n",
    "    num_array = list(str(num))\n",
    "    num_len =len(num_array)\n",
    "    numxx =0\n",
    "    for a1 in num_array:\n",
    "        numxx += int(a1) **num_len\n",
    "    if numxx ==num:\n",
    "        return True\n",
    "def print_sxh(n,m):\n",
    "    for x in range(100,m):\n",
    "        if if_sxh_num(x):\n",
    "            print(x,end =\"-\")\n",
    "            \n",
    "             \n",
    "print_sxh(145,1111111116695845848400000000000)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 什么是分解质因数？我们来百度一下：把一个合数分解成若干个质因数的乘积的形式，即求质因数的过程叫做分解质因数。\n",
    "\n",
    "# Python练习题问题如下：\n",
    "# 要求：将一个正整数分解质因数；例如您输入90，分解打印90=2*3*3*5。\n",
    "# def reduceNum(n):\n",
    "#     print '{} = '.format(n),\n",
    "#     if not isinstance(n, int) or n <= 0 :\n",
    "#         print 'iplaypy.com请输入一个正确的数字 !'\n",
    "#         exit(0)\n",
    "#     elif n in [1] :\n",
    "#         print '{}'.format(n)\n",
    "#     while n not in [1] : # 循环保证递归\n",
    "#         for index in xrange(2, n + 1) :\n",
    "#             if n % index == 0:\n",
    "#                 n /= index # n 等于 n/index\n",
    "#                 if n == 1: \n",
    "#                     print index \n",
    "#                 else : # index 一定是素数\n",
    "#                     print '{} *'.format(index),\n",
    "#                 break\n",
    "# reduceNum(90)\n",
    "# reduceNum(100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
